package im.oen.gui.tools.component;

import im.oen.boot.common.utils.Checker;
import im.oen.gui.tools.constant.Const;

import javax.swing.*;
import java.awt.*;

/**
 * @author Kevin.Xu
 */
public class JModel extends JDialog {

    private Container container;

    public JModel(JFrame frame, String text, int width, int height) {
        super(frame, text, true);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setBounds(Const.SCREEN_CENTER_X - (width / 2), Const.SCREEN_CENTER_Y - (height / 2), width, height);

        this.container = this.getContentPane();
    }

    public void addComponent(Component comp, String position) {
        this.container.add(comp, position);
    }

    public void addComponent(Component comp) {
        this.container.add(comp);

    }

    public void addComponent(Component... comps) {
        if (Checker.isEmpty(comps)) {
            return;
        }
        for (Component comp : comps) {
            this.container.add(comp);
        }
    }

    protected void removeSelf() {
        this.setVisible(false);
        this.dispose();
    }
}
